//
//  DMResponseModel.m
//  DaMaoMall
//
//  Created by HXHL-wally on 16/8/1.
//  Copyright © 2016年 daMao-wally. All rights reserved.
//

#import "DMResponseModel.h"
#import "NSURLRequest+DMNetworking.h"

NSString * const DMNetworkingResponseErrorKey = @"xyz.ypli.error.responsee";

@implementation DMResponseError
@dynamic message;
- (instancetype)initWithMessage:(NSString *)message
                           code:(NSInteger)code
                      requestId:(NSInteger)requestId {
    NSDictionary *userInfo = [NSDictionary dictionaryWithObject:message
                                                         forKey:NSLocalizedDescriptionKey];
    self = [super initWithDomain:DMNetworkingResponseErrorKey code:code userInfo:userInfo];
    if (self) {
        _requestId = requestId;
    }
    return self;
}


+ (DMResponseError *)errorWithMessage:(NSString *)message
                                 code:(NSInteger)code
                            requestId:(NSInteger)requestId {
    return [[self alloc] initWithMessage:message code:code requestId:requestId];
}
#pragma mark - 
- (NSString *)message {
    return [self localizedDescription];
}
#pragma mark -
- (NSString *)description {
    return [NSString stringWithFormat:@"[%lu]code:%lu, message:%@",self.requestId,self.code,self.message];
}
@end

@implementation DMResponseModel
- (instancetype)initWithResponseString:(NSString *)responseString
                             requestId:(NSInteger)requestId
                               request:(NSURLRequest *)request
                          responseData:(NSData *)responseData
                                status:(DMResponseStatus)status {
    self = [super init];
    if (self) {
        _contentString = responseString;
        _requestId = requestId;
        _responseData = responseData;
        _request = request;
        _requestParams = request.dm_requestParams;
    }
    return self;
}
@end
